package suzf.top.base.ui.fragment

import android.os.Bundle
import org.jetbrains.anko.support.v4.toast
import suzf.top.base.common.BaseApplication
import suzf.top.base.injection.component.ActivityComponent
import suzf.top.base.injection.component.DaggerActivityComponent
import suzf.top.base.injection.module.ActivityModule
import suzf.top.base.injection.module.LifecycleProviderModule
import suzf.top.base.presenter.BasePresenter
import suzf.top.base.presenter.view.BaseView
import javax.inject.Inject

/**
 *
 *========================
 * Created with AndroidStudio
 * Author:Mr.Su
 * Date:2019-09-07
 * Time:20:49
 * ========================
 */
open abstract class BaseMvpFragment<T: BasePresenter<*>>: BaseFragment(),BaseView {

    abstract fun injectComponent()

    @Inject
    lateinit var mPresenter: T

    lateinit var activityComponent: ActivityComponent

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        initActivityInjection()
        injectComponent()
    }

    private fun initActivityInjection() {
        //TODO   .activityModule(ActivityModule(this!!.activity!!))这一行代码的this!!.activity!! 有疑问
        activityComponent = DaggerActivityComponent.builder()
                .appComponent((activity!!.application as BaseApplication).appComponent)
                .activityModule(ActivityModule(this!!.activity!!))
                .lifecycleProviderModule(LifecycleProviderModule(this))
                .build()
    }

    override fun showLoading() {
    }

    override fun hideLoading() {
    }

    override fun onError(text: String) {
        toast(text)
    }
}